package com.jblapp.msg.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;


public class LeaveMsg {
	public boolean sendMsg(String from,String to, String msg) throws Exception {
		String url = "http://icu.joblean.com.cn/friend.php?action=insertMessage";
		boolean isSend = false;
		SendMsg sendMsg = new SendMsg();
		List<NameValuePair> parms = new ArrayList<NameValuePair>();
		parms.add(new BasicNameValuePair("name", from));
		parms.add(new BasicNameValuePair("tel", to));
		parms.add(new BasicNameValuePair("msg", msg));
		parms.add(new BasicNameValuePair("time", DateUtils.yyyyMMddhhmmss(new Date())));
		isSend = (Boolean) sendMsg.httpPostMethod(url, parms);
		if (isSend) {
			return true;
		}
		return false;
	}

	public boolean deleteMsg(String phone) throws Exception {
		String url = "http://icu.joblean.com.cn/friend.php?action=updataSuccess";
		boolean isSuccess = false;
		List<NameValuePair> parms = new ArrayList<NameValuePair>();
		parms.add(new BasicNameValuePair("tel", phone));
		SendMsg msgUtils = new SendMsg();
		isSuccess = (Boolean) msgUtils.httpPostMethod(url, parms);
		if (isSuccess) {
			return true;
		}
		return false;
	}

	public List checkMsg(String phone) throws Exception {
		String url = "http://icu.joblean.com.cn/friend.php?action=showUnReadMessage";
		List<NameValuePair> parms = new ArrayList<NameValuePair>();
		parms.add(new BasicNameValuePair("tel", phone));
		CheckUnReadMsg msgUtils = new CheckUnReadMsg();
		return (List<Msg>) msgUtils.httpPostMethod(url, parms);
	}
	
	public boolean feedBack(String from,String to, String msg) throws Exception {
		String url = "http://icu.joblean.com.cn/friend.php?action=insertFeedbackMsg";
		boolean isSend = false;
		SendMsg sendMsg = new SendMsg();
		List<NameValuePair> parms = new ArrayList<NameValuePair>();
		parms.add(new BasicNameValuePair("sender", from));
		parms.add(new BasicNameValuePair("receiver", to));
		parms.add(new BasicNameValuePair("msg", msg));
		isSend = (Boolean) sendMsg.httpPostMethod(url, parms);
		if (isSend) {
			return true;
		}
		return false;
	}
}
